//创建用户相关的小仓库
import { defineStore } from 'pinia'
//引入接口
// import { reqLogin, reqUserInfo, reqLogout } from '@/api/user'
//引入路由(常量路由)
// import { constantRoute, asnycRoute, anyRoute } from '@/router/routes'
import router from '@/router'

//创建用户小仓库
const useUserStore = defineStore('User', () => {
  let user = ref({})
  let authToken=ref('')
  function loginIn(item) {
    user.value = item
  }
  function setToken(item) {
    authToken.value = item
  }
  function logout(item) {
    //清除token
    localStorage.removeItem('user')
    localStorage.removeItem('token')
    //清除用户信息
    user.value = {}
    authToken.value = ''
    //跳转到登录页
    router.push('/login')
  }
  return {
    setToken,
    logout,
    loginIn,
    user
  }
}, {
  persist: true, //开启持久化存储
})
//对外暴露获取小仓库方法
export {
  useUserStore
} 
